'use strict';

/**
 * @ngdoc function
 * @name jgappApp.controller:FinanceFJkdCtrl
 * @description
 * # FinanceFJkdCtrl
 * Controller of the jgappApp
 */
angular.module('jgappApp')
    .controller('FinanceFJkdCtrl', function ($scope, $rootScope, openApi, Util, $routeParams, FormSubmit) {
        var id = $scope.process_id = $routeParams.id;
        $scope.showSearchPicker = function() {
            $scope.searchtitle = "收款人";
            $scope.apiurl = openApi.getBorrowHistoryRecord;
            $scope.showSearchInput = true;
            $rootScope.$emit("showmasker");
          };
          $scope.handleSearch = function(data) {
            $scope.param.receivePerson = data[0];
            $scope.param.receiveAccount = data[1];
            $scope.param.receiveBank = data[2];
            hideSearchPicker();
          };
          var hideSearchPicker = function() {
            $rootScope.$emit("closemasker");
            $scope.showSearchInput = false;
          };
          $scope.$on("closemasker", function() {
            hideSearchPicker();
          });

        $scope.submit = function (operationId) {

            // 底部类型end
            var options = {};
            // 流程id
            options.id = id;
            // 根据operationId判断是草稿还是提交
            options.operationId = operationId;
            options.urlParam = openApi.borrowMoney;
            options.param = angular.copy($scope.param, {});
            FormSubmit.submit(options,$scope);
        };
        $scope.validate = function () {
            if (!$scope.param.borAmount) {
                if ($scope.param.borAmount !== 0) {
                    Util.Toast("请填写借款金额");
                    return;
                }
            }
            if (!$scope.param.borrowReason) {
                Util.Toast("请填写借款事由");
                return;
            }
            if (!$scope.param.returnDate) {
                Util.Toast("请填写归还日期");
                return;
            }
            if ($scope.param.relatedModuleName && $scope.param.relatedModuleName !== '无') {
                if (!$scope.param.moduleNo) {
                    Util.Toast("请选择模块编号");
                    return;
                }
            }
            if (!$scope.validation.passvalidation) {
                Util.Toast($scope.validation.tip);
                return;
            }
            return true;
        }

        // 初始化逻辑,如果是修改页面的话则先从接口请求数据回显，再将缓存中的跳转来源删除，方便页面跳转返回之后的回显
        var init = function () {
            // 获取回显的详细信息
            Util.getDetailData(id, function (data) {
                $scope.param = data;
            });
        };
        // 初始化
        init();
    });
